<?php
defined('BASEPATH') OR exit('No direct script access allowed');

use \QCloud_WeApp_SDK\Auth\LoginService as LoginService;
use QCloud_WeApp_SDK\Constants as Constants;
use QCloud_WeApp_SDK\Mysql\Mysql as DB;
use \QCloud_WeApp_SDK\Model\User as Usera;

class User extends CI_Controller {

    public function __construct(){
        parent::__construct();
        $this->load->database();
        $this->load->model('user_model');
        $this->load->model('courier_model');
        $this->load->model('box_model');
        $this->load->model('order_model');
        $this->load->library('form_validation');//加载表单验证类库
        $this->load->helper('json');
        $this->load->helper('common');
        $this->output->set_content_type('application/html;charset=utf-8');
    }

    public function index() {
        $result = LoginService::check();

        if ($result['loginState'] === Constants::S_AUTH) {
            $result['userinfo']['uid'] = $result['uid'];
            $result['userinfo']['phone'] = $result['phone'];
            $result['userinfo']['deposit'] = $result['deposit'];
            $this->json([
                'code' => 0,
                'data' => $result['userinfo']
            ]);
        } else {
            $this->json([
                'code' => -1,
                'data' => []
            ]);
        }
    }

    // 用户输入物流单号
    function update_order_tracking_number(){
        $post = $this->input->post();
        if($post['tracking_number'] && $post['uid'] && $post['order_id']){
            $sql = "select user_id,receiver_user_id from app_order where id = ".$post['order_id'];
            $order_info = $this->db->query($sql)->row_array();
            if($order_info && ($order_info['user_id'] == $post['uid'] || $order_info['receiver_user_id'] == $post['uid'])){
                $bool=$this->db->where(array("id"=>$post['order_id']))->update('app_order',array("tracking_number"=>$_POST['tracking_number']));
                if($bool){
                    $tracking_info = $this->order_model->order_logistics($post['tracking_number']);
                    send_json(array('code'=>0,'data'=>array('tracking_info'=>$tracking_info),'msg'=>"保存成功"));
                }else{
                    send_json(array('code'=>-1,'data'=>'','msg'=>"保存失败"));
                }
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"该用户没有权限"));
            }
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }
    }

    // 客户手机号码保存
    public function save_phone()
    {
        $post = $this->input->post();
        if($post['uid'] && $post['phone'] && $post['code'])
        {
            // 校验验证码
            $this->confirm_code_gerenal($post['phone'],$post['code']);
            $bool=$this->db->where(array("id"=>$post['uid']))->update('app_user',array("phone"=>$post['phone']));
            if($bool)
            {
                send_json(array('code'=>0,'data'=>'','msg'=>"保存成功"));
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"保存失败"));
            }

        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"缺少参数"));
        }
    }

    // 我的寄件人
    function my_receiver_list(){
        if($_GET['uid']){
            $uid = $_GET['uid'];
            $sql = "select au.id,aw.nick_name,aw.avatar_url,aw.open_id,aw.create_time from app_user as au LEFT JOIN app_wechat AS aw ON au.wechat_id = aw.id WHERE au.id IN (select receiver_user_id from app_user_receiver WHERE user_id = $uid) ORDER BY id DESC ";
            $desc['page'] = isset($_GET['page'])?(int)$_GET['page']:1;
            $desc['psize'] = isset($_GET['psize'])?(int)$_GET['psize']:10;
            $limit_from = ($desc['page']-1)*$desc['psize'];
            $sql.=" limit ".$limit_from.",".$desc['psize'];
            $my_receiver_list = $this->db->query($sql)->result_array();
            send_json(array('code'=>0,'data'=>array('my_receiver_list'=>$my_receiver_list),'msg'=>"success"));
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"缺少参数"));
        }
    }

    // 消息提醒列表
    function my_message_list(){
        if($_GET['uid']){
            $uid = $_GET['uid'];
            $sql = "select id,receiver_id,title,content,user_box_id,created_at from app_message_history WHERE receiver_type = 1 AND receiver_id = $uid ORDER BY id DESC ";
            $desc['page'] = isset($_GET['page'])?(int)$_GET['page']:1;
            $desc['psize'] = isset($_GET['psize'])?(int)$_GET['psize']:10;
            $limit_from = ($desc['page']-1)*$desc['psize'];
            $sql.=" limit ".$limit_from.",".$desc['psize'];
            $my_receiver_list = $this->db->query($sql)->result_array();
            send_json(array('code'=>0,'data'=>array('my_message_list'=>$my_receiver_list),'msg'=>"success"));
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"缺少参数"));
        }
    }

    // 客户信息详情
    function user_info() {
        if(isset($_GET['uid']) && $_GET['uid']){
            $user_info = $this->user_model->query_wechat_info_by_id($_GET['uid']);
            $address_list = $this->user_model->query_user_address_info_by_uid($_GET['uid']);
            send_json(array('code'=>0,'data'=>array('user_info'=>$user_info,'address_list'=>$address_list)));
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"缺少参数"));
        }
    }

    // 保存用户手机号
    function save_user_phone(){
        $post = $this->input->post();
        if($post['phone'] && $post['code'] && $post['uid'])
        {
            // 手机号码校验
            if(!is_mobile($post['phone'])){
                send_json(array('code'=>-1,'data'=>'','msg'=>"请输入正确的手机号码"));
            }
            // 校验验证码
            $this->confirm_code_gerenal($post['phone'],$post['code']);
            // 数据
            $bool=$this->db->where(array("id"=>$post['uid']))->update('app_user',array("phone"=>$post['phone']));
            if($bool)
            {
                send_json(array('code'=>0,'data'=>'','msg'=>"保存成功"));
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"保存失败"));
            }

        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }

    }


    // 删除客户地址
    function delete_user_address(){
        $post = $this->input->post();
        if(check_param($post,['id','user_id'])){
            $sql = "select * from app_address WHERE id = ".$post['id']." and user_id =".$post['user_id'];
            $query = $this->db->query($sql);
            $res = $query->row_array();
            if(!$res){
                send_json(array('code'=>-1,'data'=>'','msg'=>"没有该地址或无权修改"));
            }
            $sql = "DELETE FROM app_address WHERE id = ".$post['id'];
            $bool = $this->db->query($sql);
            if($bool){
                send_json(array('code'=>0,'data'=>'','msg'=>"删除成功"));
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"删除失败"));
            }
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"缺少参数"));
        }
    }

    // 修改客户地址
    function update_user_address(){
        $post = $this->input->post();
        if(check_param($post,['id','user_id','tel','name','address'])){
            $sql = "select * from app_address WHERE id = ".$post['id']." and user_id =".$post['user_id'];
            $query = $this->db->query($sql);
            $res = $query->row_array();
            if(!$res){
                send_json(array('code'=>-1,'data'=>'','msg'=>"没有该地址或无权修改"));
            }
            $up_data['tel'] = $post['tel'];
            $up_data['name'] = $post['name'];
            $up_data['address'] = $post['address'];
            $bool=$this->db->where(array("id"=>$post['id']))->update('app_address',$up_data);
            $sql = "select * from app_address WHERE id = ".$post['id']." and user_id =".$post['user_id'];
            $query = $this->db->query($sql);
            $res2 = $query->row_array();
            if($bool){
                send_json(array('code'=>0,'data'=>array('address_info'=>$res2),'msg'=>"更新成功"));
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"更新失败"));
            }
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"缺少参数"));
        }
    }

    // 客户地址列表页
    function user_address_list(){
        if($_GET['uid'])
        {
            $list = $this->user_model->user_address_list($_GET);
            if($list){
                send_json(array('code'=>0,'data'=>$list));
            }else{
                send_json(array('code'=>0,'data'=>'','msg'=>"没有数据"));
            }
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"缺少参数"));
        }
    }

    // 保存客户地址
    function save_user_address(){
        $post = $this->input->post();
        if($post['tel'] && $post['code'] && $post['uid'] && $post['address'])
        {
            // 手机号码校验
            if(!is_mobile($post['tel'])){
                send_json(array('code'=>-1,'data'=>'','msg'=>"请输入正确的手机号码"));
            }
            // 校验验证码
            $this->confirm_code_gerenal($post['tel'],$post['code']);
            // 数据
            $data_arr['user_id'] = $post['uid'];
            $data_arr['name'] = $post['name'];
            $data_arr['tel'] = $post['tel'];
            $data_arr['address'] = $post['address'];
            $this->db->insert("app_address",$data_arr);
            $insert_id = $this->db->insert_id();
            if($insert_id)
            {
                send_json(array('code'=>0,'data'=>array('id'=>$insert_id),'msg'=>"保存成功"));
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"保存失败"));
            }

        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }

    }

    // 发送短信验证码
    public function send_msg(){
        if($_POST['tel']){
            // 手机号码校验
            if(!is_mobile($_POST['tel'])){
                send_json(array('code'=>-1,'data'=>'','msg'=>"请输入正确的手机号码"));
            }
            session_id($this->config->item("code_session_id"));
            session_start(600); //600秒以后过期。
            $code = generate_code();
            $info = "【黑凤梨供应链】您的验证码是".$code;
            $apikey = $this->config->item('apikey');
            $res = send_msg($_POST['tel'],$info,$code,$apikey);
            $session_id = $this->config->item("code_session_id");
            if($res['status']){
                send_json(array('code'=>0,'data'=>array('code'=>'','session_id'=>$session_id),'msg'=>'发送成功'));
            }else{
                send_json(array('code'=>-1,'msg'=>$res['msg']));
            }

        }else{
            send_json(array('code'=>-1,'msg'=>'参数不全'));
        }

    }

    /**  验证短信验证码
     * @param string $tel 手机号
     * @param string $code 输入验证码
     * @return bool
     */
    function confirm_code_gerenal($tel="",$code=""){
        session_id($this->config->item("code_session_id"));
        session_start();
        $rs = isset($_SESSION[$tel."code"]) ? $_SESSION[$tel."code"] : '';
        if($rs){
            $data = json_decode($rs,true);
            $minute=floor((time()-strtotime($data['time']))%86400/60);
            if($minute>5){
                send_json(array('code'=>-1,'data'=>'','msg'=>"此验证码已超过5分钟,已失效"));
            }
            if($data['code'] == $code){
                return true;
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"验证码错误"));
            }
        }else{
             send_json(array('code'=>-1,'data'=>'','msg'=>"此手机没有发送验证码"));
        }
    }
    //确认验证码
    function confirm_code(){
        $post = $this->input->post();
        if(isset($post['tel']) && isset($post['code']) && isset($post['session_id'])){
            $res = $this->confirm_code_gerenal($post['tel'],$post['code']);
            if($res)
            {
                send_json(array('code'=>0,'data'=>'','msg'=>"验证成功"));
            }
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }
    }


    // 呼叫快递
    function call_courier(){

        if($_POST['uid'])
        {
            $re = $this->user_model->query_app_user_box($_POST['uid'],[1,2,3]);
            if($re){
                if($re[0]['status'] == 2)
                {
                    $res = $re[0];
                    // 查询接单人的信息
                    $courier_info = $this->courier_model->query_courier_info($res['courier_id']);
                    if($courier_info)
                    {
                        $res['real_name'] = $courier_info['real_name'];
                        $res['tel'] = $courier_info['tel'];
                        $res['company'] = $courier_info['company'];
                        $res['code'] = $courier_info['code'];
                        $res['bn'] = $courier_info['bn'];
                        $res['remark'] = $courier_info['remark'];
                        $res['state'] = '3';
                    }
                    // 有人接单
                    send_json(array('code'=>0,'data'=>$res,'msg'=>"有人接单啦"));
                }else if($re[0]['status'] == 3){
                    // 快递员申请了结束服务
                    send_json(array('code'=>0,'data'=>array('id'=>$re[0]['id'],'state'=>4),'msg'=>"请先结束当前快递员的服务"));

                }else{
                    // 正在呼叫
                    send_json(array('code'=>0,'data'=>array('id'=>$re[0]['id'],'state'=>2),'msg'=>"正在召唤"));
                }

            }
            if($_POST['type'] && $_POST['address_id'])
            {
                // 需要箱子
                if($_POST['type'] == 1)
                {
                    // 新建一条召唤信息
                    $box_list = isset($_POST['box_list']) ? json_decode($_POST['box_list'],true) : '';
                    foreach ($box_list as $k => $box)
                    {
                        if($box['num'] == 0)
                        {
                            // 箱子数量不能为0
                            unset($box_list[$k]);
                        }
                    }
                    if(empty($box_list))
                    {
                        send_json(array('code'=>-1,'data'=>'','msg'=>"箱子数量不能全部为0"));
                    }
                    $res = $this->user_model->save_user_box_info($_POST['uid'],1,1,$_POST['address_id'],$box_list);
                    if($res){
                        send_json(array('code'=>0,'data'=>array('id'=>$res),'msg'=>"正在召唤"));
                    }
                }else{
                    // 归还箱子
                    $res = $this->user_model->save_user_box_info($_POST['uid'],2,1,$_POST['address_id'],'');
                    if($res){
                        send_json(array('code'=>0,'data'=>array('id'=>$res),'msg'=>"正在召唤"));
                    }
                }
            }else{
                send_json(array('code'=>0,'data'=>array('state'=>1),'msg'=>"请先呼叫快递"));
            }

        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }

    }

    // 取消召唤
    function cancel_courier(){
       $id = $_POST['id'];
       //查询单子状态
        $res = $this->courier_model->get_app_user_box($id);
        if($res['status'] == 1 || $res['status'] == 2)
        {
            $bool=$this->db->where(array("id"=>$id))->update('app_user_box',array("status"=>0));
            if($bool)
            {
                send_json(array('code'=>0,'data'=>'','msg'=>"取消成功"));
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"取消失败"));
            }
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"当前状态无法取消"));
        }

    }

    // 历史快递员
    function history_courier(){
        if(isset($_GET['uid']) && $_GET['uid']){
            $sql = "SELECT
  aub.user_id,
  aub.type,
  aub.status,
  aub.created_at,
  aub.courier_id,
  aub.created_at,
  aw.nick_name,
  aw.open_id,
  aw.avatar_url
FROM app_user_box AS aub LEFT JOIN app_courier ac ON ac.id = aub.courier_id
  LEFT JOIN app_wechat AS aw ON aw.id = ac.wechat_id
WHERE aub.courier_id IS NOT NULL AND aub.user_id = ".$_GET['uid'];
            // 排序
            $sql.=" order by aub.created_at desc";
            // 分页
            $desc['page'] = isset($_GET['page'])?(int)$_GET['page']:1;
            $desc['psize'] = isset($_GET['psize'])?(int)$_GET['psize']:10;
            $limit_from = ($desc['page']-1)*$desc['psize'];
            $sql.=" limit ".$limit_from.",".$desc['psize'];
            $history_courier_list = $this->db->query($sql)->result_array();

            send_json(array('code'=>0,'data'=>array('history_courier_list'=>$history_courier_list),'msg'=>"success"));

        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }

    }

    // 用户确认服务结束
    public function insure_service_end()
    {
        $post = $this->input->post();
        if($post['uid'] && $post['service_id'])
        {
            $user_box_info = $this->courier_model->get_app_user_box($post['service_id']);
            if(!$user_box_info)
            {
                send_json(array('code'=>-1,'data'=>'','msg'=>"服务不存在"));
            }
            if($user_box_info['status'] == 4){
                send_json(array('code'=>-1,'data'=>'','msg'=>"服务已经结束"));
            }
            if($user_box_info['user_id'] != $post['uid'])
            {
                send_json(array('code'=>-1,'data'=>'','msg'=>"无权操作"));
            }
            // 修改app_user_box 状态
            $bool=$this->db->where(array("id"=>$post['service_id']))->update('app_user_box',array("status"=>4));
            if($bool)
            {
                send_json(array('code'=>0,'data'=>'','msg'=>"success"));
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"修改失败"));
            }

        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }
    }

    // 用户可确认服务结束的
    public function insure_service_end_list()
    {
        $post = $this->input->post();
        if($post['uid'])
        {
            $sql = "select * from app_user_box WHERE user_id = ".$post['uid']." and status = 3";
            $query = $this->db->query($sql);
            $res = $query->row_array();
            send_json(array('code'=>0,'data'=>$res,'msg'=>"success"));
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }

    }

    // 用户申请退押金
    public function return_deposit()
    {
        $post = $this->input->post();
        if($post['uid'] && $post['wechat'])
        {
            // 是否已经冻结
            $user_info = $this->user_model->query_wechat_info_by_id($post['uid']);
            if($user_info['status'] == 0)
            {
                send_json(array('code'=>-1,'data'=>'','msg'=>"账户已被冻结，无法操作"));
            }

            $data_arr['user_id'] = $post['uid'];
            $data_arr['wechat'] = $post['wechat'];
            $data_arr['verify_status'] = 0;
            $data_arr['created_at'] = date("Y-m-d H:i:s");
            $sql = "select * from app_user_return_deposit WHERE user_id = ".$post['uid']." order by id desc limit 1";
            $query = $this->db->query($sql);
            $res = $query->row_array();
            if($res){
                if($res['verify_status'] == 0){
                    send_json(array('code'=>0,'data'=>'','msg'=>"已经申请审批，请耐心等待"));
                } else if($res['verify_status'] == 1){
                    send_json(array('code'=>0,'data'=>'','msg'=>"审批已通过，请勿重复申请"));
                } else {
                    $this->db->insert("app_user_return_deposit",$data_arr);
                    $insert_id = $this->db->insert_id();
                    if($insert_id)
                    {
                        send_json(array('code'=>0,'data'=>array('reason'=>$res['verify_reason']),'msg'=>"审批未通过，已再次申请"));
                    }else{
                        send_json(array('code'=>-1,'data'=>'','msg'=>"审批未通过，数据保存失败，请联系商家"));
                    }

                }
            }
            $this->db->insert("app_user_return_deposit",$data_arr);
            $insert_id = $this->db->insert_id();
            if($insert_id)
            {
                send_json(array('code'=>0,'data'=>'','msg'=>"申请成功"));
            }else{
                send_json(array('code'=>-1,'data'=>'','msg'=>"数据保存失败，请联系商家"));
            }

        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }
    }

    // 退押金最新进度
    public function return_deposit_status()
    {
        if($_GET['uid']) {
            $sql = "select * from app_user_return_deposit WHERE user_id = " . $_GET['uid'] . " order by id desc limit 1";
            $query = $this->db->query($sql);
            $res = $query->row_array();
            if($res){
                send_json(array('code'=>0,'data'=>array('verify_status'=>$res['verify_status'],'verify_reason'=>$res['verify_reason'],'created_at'=>$res['created_at']),'msg'=>"success"));
            }else{
                send_json(array('code'=>0,'data'=>array('verify_status'=>'3'),'msg'=>"没有申请退押金"));
            }
        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }
    }

    // 用户扫码开箱
    public function user_sm()
    {
        if($_POST['user_id'] && $_POST['box_bn']){
            $info = $this->box_model->query_box_by_bn($_POST['box_bn']);
            if(!$info){
                send_json(array('code'=>-1,'data'=>'','msg'=>"这个箱子的编号不存在"));
            }
            if($info['use_status'] == 1)
            {
                // 是否已经冻结
                $user_info = $this->user_model->query_wechat_info_by_id($_POST['user_id']);
                if($user_info['status'] == 0)
                {
                    send_json(array('code'=>-1,'data'=>'','msg'=>"账户已被冻结，无法操作"));
                }
                // 箱子未开箱，客户开箱
                send_json(array('code'=>0,'data'=>array('call_back_code'=>1,'call_back'=>'box/user_open_box'),'msg'=>"success"));
            }
            if($info['use_status'] == 2)
            {
                // 快递员送来的
                // 有订单信息判断权限
                $order_info = $this->order_model->query_order_by_box_id($info['id']);
                if($order_info)
                {
                    if($order_info['user_id'] != $_POST['user_id'] && $order_info['receiver_user_id'] != $_POST['user_id'] )
                    {
                        send_json(array('code'=>-1,'data'=>'','msg'=>"没有权限开箱"));
                    }
                    if($order_info['user_id'] == $_POST['user_id'] )
                    {
                        // 用户随意开箱
                        // 运输途中开箱，不影响箱子的归属
                        send_json(array('code'=>0,'data'=>array('call_back_code'=>2,'call_back'=>'box/user_open_box_now'),'msg'=>"success"));
                    }else{
                        // 接受方扫码开箱
                        send_json(array('code'=>0,'data'=>array('call_back_code'=>3,'call_back'=>'box/receiver_open_box'),'msg'=>"success"));
                    }

                }
                // 箱子未开箱，客户开箱
                send_json(array('code'=>0,'data'=>array('call_back_code'=>1,'call_back'=>'box/user_open_box'),'msg'=>"success"));
            }
            if($info['use_status'] == 3)
            {
                // 判断用户身份
                $order_info = $this->order_model->query_order_by_box_id($info['id']);
                if(!$order_info)
                {
                    send_json(array('code'=>-1,'data'=>'','msg'=>"没有权限开箱，订单不存在"));
                }
                if($order_info['user_id'] != $_POST['user_id'] && $order_info['receiver_user_id'] != $_POST['user_id'] )
                {
                    send_json(array('code'=>-1,'data'=>'','msg'=>"没有权限开箱"));
                }
                if($order_info['user_id'] == $_POST['user_id'])
                {
                    // 运输途中开箱，不影响箱子的归属
                    send_json(array('code'=>0,'data'=>array('call_back_code'=>2,'call_back'=>'box/user_open_box_now'),'msg'=>"success"));
                }
                elseif($order_info['receiver_user_id'] == $_POST['user_id'])
                {
                    // 接受方开箱
                    send_json(array('code'=>0,'data'=>array('call_back_code'=>3,'call_back'=>'box/receiver_open_box'),'msg'=>"success"));
                }

            }
            if($info['use_status'] == 4)
            {
                send_json(array('code'=>-1,'data'=>'','msg'=>"该箱子已经停止使用"));
            }
            if($info['use_status'] == 5)
            {
                send_json(array('code'=>-1,'data'=>'','msg'=>"该箱子已经被禁用"));
            }

        }else{
            send_json(array('code'=>-1,'data'=>'','msg'=>"参数不全"));
        }
    }


    public function output_tests() {
        $open_id = 12313;
        $userinfo = new stdClass();
        $s1 = new stdClass();
        $s1->timestamp = '1513240195';
        $s1->appid = 'wx03a233d5dbd0c120';

        $userinfo->openId = 'oIC310D09CGy3kTyCWF8p7NYBvyA';
        $userinfo->nickName = '我觉得OK';
        $userinfo->gender = '1';
        $userinfo->city = '';
        $userinfo->province = '';
        $userinfo->country = 'Egypt';
        $userinfo->avatarUrl = 'https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLFZtLbKMvIUqjde9BsjZDJvNjfArlfsg03ziaiaex4VGa0IZEkKV2eodmZiao8ts2xhcYDVdXdSSrmw/0';
        $userinfo->watermark = $s1;


        Usera::storeUserInfo($userinfo, '33ee5a00151feafc9c4375f5930688cb59580560', 'Mlm8BpkMGjwgy2ye0i/Jeg==');
        $re = DB::row('app_wechat', ['*'], compact('open_id'));
        send_json(array('res'=>$re));
    }
}
